package biz.datalk.industrialland.admin.modules.redisdelay.stragety;

import biz.datalk.industrialland.common.exception.ValidateException;
import biz.datalk.industrialland.common.result.UnifyResultCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * @author tarofang@163.com
 * @date 2024-01-29
 */
@Getter
@Setter
@ToString
public class DsVOWrapper implements Serializable {
    private static final long serialVersionUID = 1L;

    private String errCode;
    private String errMsg;

    public static DsVOWrapper create(String errCode, String errMsg) {
        if (StringUtils.isBlank(errCode)) {
            throw new ValidateException("The errCode must not be blank.");
        }
        DsVOWrapper vo = new DsVOWrapper();
        vo.setErrCode(errCode);
        vo.setErrMsg(errMsg);
        return vo;
    }

    public static DsVOWrapper fail(String errCode, String errMsg) {
        return create(errCode, errMsg);
    }

    public static DsVOWrapper fail(String errMsg) {
        return create(UnifyResultCode.SERVICE_ERROR, errMsg);
    }

    public static DsVOWrapper fail() {
        return create(UnifyResultCode.SERVICE_ERROR, "操作失败");
    }

    public static DsVOWrapper success() {
        return create(UnifyResultCode.SUCCESS, "操作成功");
    }

    public boolean isSuccess() {
        return UnifyResultCode.SUCCESS.equals(this.errCode);
    }
}
